package com.global.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.global.dao.ReportCategoryDao;
import com.global.model.ReportCategory;

@Repository("reportCategoryDao")
public class ReportCategoryDaoImpl extends GenericDaoHibernate<ReportCategory, Long>  implements ReportCategoryDao {

	public ReportCategoryDaoImpl() {
		super(ReportCategory.class);
	}

    /**
     * {@inheritDoc}
     */
	public ReportCategory saveCategoty(ReportCategory category) {
		if(category!=null){
	        if (log.isDebugEnabled()) {
	            log.debug("category's id: " + category.getId());
	        }
	        getHibernateTemplate().saveOrUpdate(category);
	        getHibernateTemplate().flush();
		}
		
		return category;
	}

    /**
     * {@inheritDoc}
     */
	public boolean saveBatchCategoty(List<ReportCategory> categoryList) {
		if(categoryList!=null){
			getHibernateTemplate().saveOrUpdateAll(categoryList);
			getHibernateTemplate().flush();
			
			return true;
		}
		
		return false;
	}

    /**
     * {@inheritDoc}
     */
	public ReportCategory getReportCategory(String name) {
        HashMap<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put("uniqueName", name);
		List<ReportCategory> list = this.findByNamedQuery("findReportCategotyByName", queryParams);
		if(!list.isEmpty()){
			return list.get(0);
		}
		
		return null;
	}
	
    /**
     * {@inheritDoc}
     */
	public List<ReportCategory> getReportCategoryList() {
		return getAll();
	}
}
